#! /usr/bin/env python
import random
def genbits(numzeroes, numones, filename='temp.tbits', randseed = None):
    f = open (filename, 'w')
    if (randseed != None):
        random.seed(randseed) 
    while (numzeroes + numones > 0):
        if (random.randint(1,numzeroes+numones) <= numzeroes):
            f.write('0')
            numzeroes = numzeroes - 1
        else: 
            f.write('1')
            numones  = numones -1
    f.close()

if __name__ == "__main__":
    import sys
#    print(sys.argv)
    if len(sys.argv)==3:
        genbits(int(sys.argv[1]), int(sys.argv[2]))
    elif len(sys.argv)==4:
        genbits(int(sys.argv[1]), int(sys.argv[2]), sys.argv[3])
    elif len(sys.argv)==5:
        genbits(int(sys.argv[1]), int(sys.argv[2]), sys.argv[3])
    else:
        print "Usage: python ",sys.argv[0], " numzeroes numones [filename=temp.tbits] [randseed]"  
        
